package gov.pbc.nn.kjgl.task.handler;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.alibaba.druid.util.StringUtils;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.handler.NodeEventHandler;
import com.bstek.uflo.process.node.Node;

import gov.pbc.nn.core.dao.CommonHibernateDao;
import gov.pbc.nn.kjgl.task.entity.TaskEntity;

@Component(EndNodeEventHandler.BEAN_ID)
public class EndNodeEventHandler implements NodeEventHandler {

	public static final String BEAN_ID = "gov.pbc.nn.kjgl.task.handler.EndNodeEventHandler";

	@Resource(name = CommonHibernateDao.BEAN_ID)
	private CommonHibernateDao hibernateDao;

	@Override
	public void enter(Node arg0, ProcessInstance arg1, Context arg2) {

	}

	@Override
	public void leave(Node arg0, ProcessInstance arg1, Context arg2) {
		String businessId = arg1.getBusinessId();
		TaskEntity entity = this.hibernateDao.get(businessId, TaskEntity.class);
		if (entity.getState() != 20) {
			entity.setState(30);
			this.hibernateDao.update(entity);
		}
	}

}
